//
//  HJHeader.m
//  YaDiuDiu
//
//  Created by 胡光健 on 2017/10/28.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "HJHeader.h"
#import "HJGetOnModel.h"
#import "StarView.h"

@interface HJHeader ()



@property(nonatomic,strong)StarView *star;
@end

@implementation HJHeader


-(void)awakeFromNib {
    [super awakeFromNib];
    self.stayNum.layer.cornerRadius = 10;
    self.stayNum.layer.masksToBounds = YES;
    self.endNum.layer.cornerRadius = 10;
    self.finishNum.layer.cornerRadius = 10;
    self.endNum.layer.masksToBounds = YES;
    self.finishNum.layer.masksToBounds = YES;
    
    self.btnView.layer.borderWidth = 1;
    self.btnView.layer.borderColor = [UIColor blackColor].CGColor;
    self.btnView.layer.cornerRadius = 5;
    
    
    
}

-(instancetype)init {
    if (self = [super init]) {
        self = [[NSBundle mainBundle]loadNibNamed:@"Header" owner:self options:nil].firstObject;
    }
    return self;
}

-(void)setModel:(HJGetOnModel *)model {
    _model = model;
    
    if ([model.merchant.ison isEqualToString:@"2"]) {
        self.stauteImage.hidden = NO;
        self.stauts.selected = NO;
    }else {
        self.stauteImage.hidden = YES;
        self.stauts.selected = YES;
    }
    self.name.text = model.merchant.name;
    if ([model.merchant.automatic isEqualToString:@"2"]) {
        self.orderStatue.text =@"关闭一键自动接单";
    }else {
        self.orderStatue.text = @"开启一键自动接单";
    }
    self.star = [[StarView alloc]init];
    NSInteger index = [model.merchant.star integerValue];
    self.star.showStar = index * 20;
    [self.startView addSubview:self.star];
    [self.star makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.startView.centerX);
        make.top.equalTo(self.startView.top);
        make.width.equalTo(80);
        make.height.equalTo(16);
    }];
    
    
    self.dayCode.text = model.counttodayincome;
    self.incomeCode.text = model.todayincome;
    if ([model.wjcorder isEqualToString:@"0"]) {
        self.stayNum.hidden = YES;
    }else {
        self.stayNum.text = model.wjcorder;
    }
    if ([model.yjorder isEqualToString:@"0"]) {
        self.endNum.hidden =YES;
    }else {
        self.endNum.text = model.yjorder;
    }
    if ([model.wcorder isEqualToString:@"0"]) {
        self.finishNum.hidden = YES;
    }else {
         self.finishNum.text = model.wcorder;
    }
   
}
// 营业还是休息
- (IBAction)statueBtn:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected) {
        self.stauteImage.hidden = YES;
    }else {
        self.stauteImage.hidden = NO;
    }
    
}
- (IBAction)oderStatueBtn:(UIButton *)sender {
    
    if ([self.stauts.titleLabel.text isEqualToString:@"休息中"]) {
        [LICGToast showWithText:@"休息状态下不能开启自动接单"];
        return;
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",urlHead,@"/App/Merchantcentre/automaticorder"];
    NSString * str;
    if ([_model.merchant.automatic isEqualToString:@"2"]) {
        str =@"3";
    }else {
        str = @"2";
    }
    [TZHttpTool post:url params:@{@"id":_model.merchant.merchant_id,@"automatic":str} success:^(NSDictionary *result) {
        [LICGToast showWithText:result[@"mssage"]];
    } failure:^(NSString *msg) {
        [LICGToast showWithText:msg];
    }];
    
}



// 200 待结单 201 已接单 202 完成订单

- (IBAction)oderBtn:(UIButton *)sender {
    
    if (self.oderBtnBlock) {
        self.oderBtnBlock(sender.tag, _model.merchant.merchant_id);
    }
}


@end
